Coffee School
Code Editor
// Create our player's base entity
Crafty.e("2D, DOM, Color") // Specifying the components to add
.attr({x: 30, y: 30, w: 10, h: 10}) // Specifying the dimensions and the point to draw from
.color("#ff0000"); // Specifying the colour of the rectangle
Preview
Console Log:
Part 2: Creating the Player’s Movement System
Time estimate for this part: 10 minutes
Now that we’ve drawn the player we’ll want to think about giving the player movement. In Flappy Bird style games there are generally only two types of movement by the player:
- Movement instigated by player input - When the player “flaps”.
- Movement determined by the envrionment or game logic - The constant falling motion from a gravity-like behaviour.
Let’s start by tacking the game behaviour which makes it appear as though there is a gravitational force pulling the player’s avatar to the ground.